package com.ylr.config.framework.resolver;

import com.ylr.base.common.exception.YlrException;
import com.ylr.base.common.tool.Result;
import com.ylr.config.framework.feign.client.YcEnumClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-12 15:06:54
 * className: YcEnumResolver
 * version: 1.0
 * description:
 */
@Component
public class YcEnumResolver {

    private static final Logger log = LoggerFactory.getLogger(YcEnumResolver.class);

    @Value("${spring.application.simple-name:ylr}")
    private String applicationSimpleName;

    private final YcEnumClient ycEnumClient;

    public YcEnumResolver(YcEnumClient ycEnumClient) {
        this.ycEnumClient = ycEnumClient;
    }

    /**
     * 获取枚举值列表接口
     * @param type 枚举类型
     * @return 枚举值列表
     */
    public List<Long> getValueList(Integer type) {
        Result<List<Long>> result = ycEnumClient.getValueList(type);
        if (result.isFail()) {
            log.warn("{}模块 => 获取枚举值列表失败。message={}", applicationSimpleName, result.getMsg());
            throw new YlrException(result);
        }
        return result.getData();
    }
}
